package org.cloudie.docs.editor.client.storage.apps;

import java.util.ArrayList;
import java.util.Date;

public class AppSystem {

  private static int maxId = 0;
  private static String prefixId = "a" + (new Date()).getTime() + "-";
  private static ArrayList<AppSystemEntry> entries =
      new ArrayList<AppSystemEntry>();
  
  private AppSystem() { }
  
  public static AppSystemEntry removeEntry(String id) {
	AppSystemEntry entry = getEntry(id);
    if (entry != null) {
      entries.remove(entry);
      return entry;
    }
    return null;
  }
  
  public static void addEntry(AppSystemEntry entry) {
    entries.add(entry);
  }
  
  public static String getNextId() {
    return prefixId + ++maxId;
  }
  
  public static AppSystemEntry getEntry(String id) {
    for (AppSystemEntry entry : entries) {
      if (entry.getId().equals(id)) {
	    return entry;
      }
	}
    return null;
  }
  
  public static ArrayList<AppSystemEntry> getEntries() {
    return entries;
  }
  
  public static void setEntries(ArrayList<AppSystemEntry> allEntries) {
    for (AppSystemEntry entry : allEntries) {
      addEntry(entry);
    }
  }
  
}
